package familytree.persistencia.dao.hibernate;


import familytree.persistencia.dao.AlbumDAO;
import familytree.persistencia.dao.ArbolDAO;
import familytree.persistencia.dao.DAOFactory;
import familytree.persistencia.dao.EventoDAO;
import familytree.persistencia.dao.ImagenDAO;
import familytree.persistencia.dao.NodoDAO;
import familytree.persistencia.dao.ParejaDAO;
import familytree.persistencia.dao.UsuarioDAO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Returns Hibernate-specific instances of DAOs.
 * <p/>
 * If for a particular DAO there is no additional non-CRUD functionality, we use
 * a nested static class to implement the interface in a generic way. This allows clean
 * refactoring later on, should the interface implement business data access
 * methods at some later time. Then, we would externalize the implementation into
 * its own first-level class.
 *
 * @author Christian Bauer
 */
public class HibernateFactoryDAO extends DAOFactory {

    private static Log log = LogFactory.getLog(HibernateFactoryDAO.class);

    
    //public ItemDAO getItemDAO() {
      //  return (ItemDAO)instantiateDAO(ItemDAOHibernate.class);
    //}

   
    private HibernateGenericDAO instantiateDAO(Class daoClass) {
        try {
            log.debug("Instantiating DAO: " + daoClass);
            return (HibernateGenericDAO)daoClass.newInstance();
        } catch (Exception ex) {
            throw new RuntimeException("Can not instantiate DAO: " + daoClass, ex);
        }
    }

    @Override
    public ArbolDAO getArbolDAO() {
        return (ArbolDAO)instantiateDAO(HibernateArbolDAO.class);
    }

    @Override
    public NodoDAO getNodoDao() {
        return (NodoDAO)instantiateDAO(HibernateNodoDAO.class);
    }

    @Override
    public ParejaDAO getParejaDAO() {
        return (ParejaDAO)instantiateDAO(HibernateParejaDAO.class);
    }
    @Override
    public UsuarioDAO getUsuarioDAO() {
        return (UsuarioDAO)instantiateDAO(HibernateUsuarioDAO.class);
    }

    @Override
    public AlbumDAO getAlbumDAO() {
        return (AlbumDAO)instantiateDAO(HibernateAlbumDAO.class);
    }

    @Override
    public ImagenDAO getImagenDAO() {
        return (ImagenDAO) instantiateDAO(HibernateImagenDAO.class);
    }

    public EventoDAO getEventoDAO(){
        return (EventoDAO) instantiateDAO(HibernateEventoDAO.class);
    }
    
    // Inline concrete DAO implementations with no business-related data access methods.
    // If we use public static nested classes, we can centralize all of them in one source file.

    //Esto no lo entiendo
    //public static class CategorizedItemDAOHibernate
            //extends HibernateGenericDAO<CategorizedItem, CategorizedItem.Id>
            //implements CategorizedItemDAO {}

    
}
